package com.kris;

import java.math.BigDecimal;
import java.util.Date;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;

/**
 * 报表
 *
 * @author Kris Zhang
 */
abstract class Report {

    final long ONE_HOUR = 1000 * 60 * 60; //1小时
    final long NINE_HOUR = ONE_HOUR * 9; // 9小时
    final long HOUR_8 = ONE_HOUR * 8; // 8小时
    final long HOUR_4 = ONE_HOUR * 4; // 4小时

    abstract void make() throws Exception;

    Font createFont(Workbook wb, String fontName, short fontSize) {
        Font font = wb.createFont();
        font.setFontHeightInPoints(fontSize);
        font.setFontName(fontName);
        return font;
    }

    Font createFontArial18(Workbook wb) {
        return createFont(wb, "Arial", (short) 18);
    }

    Font createFontArial14(Workbook wb) {
        return createFont(wb, "Arial", (short) 14);
    }

    Font createFontArial12(Workbook wb) {
        return createFont(wb, "Arial", (short) 12);
    }

    /**
     * 节假日加班时长=下班时间-上班时间<br>
     * 节假日加班时长大于4个小时，小于8小时，这减少半个小时。 大约8小时，减少1个小时。
     *
     * @param beginTime
     * @param endTime
     * @return
     */
    protected double calculateHolidayWorkOverTime(Date beginTime, Date endTime) {
        //没有打卡的，都不算加班
        if (beginTime == null || endTime == null) {
            return 0;
        }
        long diff = endTime.getTime() - beginTime.getTime();
        if (diff < 0) {
            diff = 0;
        }
        if (diff > HOUR_8) {
            diff -= ONE_HOUR;
        } else if (diff > HOUR_4) {
            diff -= ONE_HOUR / 2;
        }
        double workOvertime = diff * 1.0 / ONE_HOUR;
        // 取小数点1位
        BigDecimal bg = new BigDecimal(workOvertime);
        return bg.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

 

}
